/**
 * 
 */
package schach.server.model;

import java.util.ArrayList;

/**
 * @author Freddy
 *
 */
public class Laeufer extends Figur {

	
	public Laeufer(Feld position, boolean alive, boolean black) {
		super(position, alive, black);
	}

	@Override
	public ArrayList<Feld> crossedFields(Feld f, boolean schlagen) throws NullPointerException{
		ArrayList<Feld> results = new ArrayList<Feld>();
		int deltaX = f.getX() - getPosition().getX();
		int deltaY = f.getY() - getPosition().getY();
		if (deltaX == 0 && deltaY == 0){
			throw new NullPointerException();
		}
		else if (Math.abs(deltaX) == Math.abs(deltaY)){
			if(deltaX > 0 && deltaY > 0){
				for(int i = 1; i < deltaX; i++){
					results.add(new Feld(f.getX()-i, f.getY()-i));
				}
			}
			else if(deltaX < 0 && deltaY < 0){
				for(int i = 1; i < Math.abs(deltaX); i++){
					results.add(new Feld(f.getX()+i, f.getY()+i));
				}
			}
			else if(deltaX > 0 && deltaY < 0){
				for(int i = 1; i < deltaX; i++){
					results.add(new Feld(f.getX()-i, f.getY()+i));
				}
			}
			else if(deltaX <0 && deltaY > 0){
				for(int i = 1; i < Math.abs(f.getX()); i++){
					results.add(new Feld(f.getX()+i, f.getY()-i));
				}
			}
		}
		else{
			throw new NullPointerException();
		}
		return results;

	}

}
